home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14254 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: fastest code
  5. Date: Fri, 12 Apr 96 16:31:32 GMT
  6. Organization: none
  7. Message-ID: <829326692snz@genesis.demon.co.uk>
  8. References: <316112A2.7D37@public.sta.net.cn> <4kghs7$250@news1.mnsinc.com> <4kgu7g$n9a@solutions.solon.com> <yxsbukxemoi.fsf@stint.cl.cam.ac.uk> <4kljb4$nm3@solutions.solon.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4kljb4$nm3@solutions.solon.com>
  15.            seebs@solon.com "Peter Seebach" writes:
  16.  
  17. >In article <yxsbukxemoi.fsf@stint.cl.cam.ac.uk>,
  18. >Gareth Rees <gdr11@cl.cam.ac.uk> wrote:
  19. >>Surely, under the `as if' rule, code that invokes undefined behaviour
  20. >>*at any point* need not produce the results you expect even for those
  21. >>portions that don't invoke undefined behaviour?
  22. >
  23. >True, although in practice it doesn't come up.
  24. >
  25. >>So in the case
  26. >
  27. >>    int x[17], i;
  28. >>    for (i=0; i<16; i++) x[i] = x[i+i];
  29. >
  30. >>the compiler is perfectly at liberty to optimise away the loop body
  31. >>because of the undefined behaviour of the whole program.
  32.  
  33. Yes, it is undefined by definition from ANSI/ISO 3.16 because the code uses
  34. the value of 'indeterminately valued objects' i.e. the elements of x
  35. (assuming x is defined in block scope). If x was, say, static this would be
  36. well defined.
  37.  
  38. >Right.  As it turns out, x had dimension 32 in the original post, but this
  39. >was not posted along with the loop description.
  40.  
  41. In the test program posted recently the elements of x were suitably
  42. initialised.
  43.  
  44. -- 
  45. -----------------------------------------
  46. Lawrence Kirby | fred@genesis.demon.co.uk
  47. Wilts, England | 70734.126@compuserve.com
  48. -----------------------------------------
  49.